package com.siyougame.business.controller.admin.template;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.siyougame.common.pojo.PageResult;
import com.siyougame.common.pojo.CommonResult;
import static com.siyougame.common.pojo.CommonResult.success;

import com.siyougame.common.utils.ExcelUtils;

import com.siyougame.common.annotation.OperateLog;
import static com.siyougame.common.enums.OperateTypeEnum.*;

import com.siyougame.business.controller.admin.template.vo.*;
import com.siyougame.business.dal.dataobject.template.TemplateDO;
import com.siyougame.business.convert.template.TemplateConvert;
import com.siyougame.business.service.template.TemplateService;

@Api(tags = "管理后台 - 模板")
@RestController
@RequestMapping("/openapi/business/template")
@Validated
public class TemplateController {

    @Resource
    private TemplateService templateService;

    @PostMapping("/create")

    public CommonResult<Long> createTemplate(@Valid @RequestBody TemplateCreateReqVO createReqVO) {
        return success(templateService.createTemplate(createReqVO));
    }

    @PutMapping("/update")

    public CommonResult<Boolean> updateTemplate(@Valid @RequestBody TemplateUpdateReqVO updateReqVO) {
        templateService.updateTemplate(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")

    public CommonResult<Boolean> deleteTemplate(@RequestParam("id") Long id) {
        templateService.deleteTemplate(id);
        return success(true);
    }

    @GetMapping("/get")

    public CommonResult<TemplateRespVO> getTemplate(@RequestParam("id") Long id) {
        TemplateDO template = templateService.getTemplate(id);
        return success(TemplateConvert.INSTANCE.convert(template));
    }

    //@GetMapping("/list")
    //
    //public CommonResult<List<TemplateRespVO>> getTemplateList(@RequestParam("ids") Collection<Long> ids) {
    //    List<TemplateDO> list = templateService.getTemplateList(ids);
    //    return success(TemplateConvert.INSTANCE.convertList(list));
    //}

    @GetMapping("/page")

    public CommonResult<PageResult<TemplateRespVO>> getTemplatePage(@Valid TemplatePageReqVO pageVO) {
        PageResult<TemplateDO> pageResult = templateService.getTemplatePage(pageVO);
        return success(TemplateConvert.INSTANCE.convertPage(pageResult));
    }
    //
    //@GetMapping("/export-excel")
    //@ApiOperation("导出模板 Excel")
    //@PreAuthorize("@ss.hasPermi('business:template:export')")
    //@OperateLog(type = EXPORT)
    //public void exportTemplateExcel(@Valid TemplateExportReqVO exportReqVO,
    //          HttpServletResponse response) throws IOException {
    //    List<TemplateDO> list = templateService.getTemplateList(exportReqVO);
    //    // 导出 Excel
    //    List<TemplateExcelVO> datas = TemplateConvert.INSTANCE.convertList02(list);
    //    ExcelUtils.write(response, "模板.xls", "数据", TemplateExcelVO.class, datas);
    //}

}
